package cn.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.dao.ApipraMapper;
import cn.domain.Apipra;
import cn.domain.ApipraExample;
import cn.service.ApipraService;
import cn.util.Pagination;

@Service
@Transactional(rollbackFor=Exception.class)
public class ApipraServiceImpl implements ApipraService {

	@Autowired
	private ApipraMapper apipraMapper;

	@Override
	public void insert(Apipra  apipra) {
		apipraMapper.insert(apipra);
	}


	@Override
	public int getAllCount(Apipra  apipra) {
		return apipraMapper.getAllCount(apipra);
	}


	@Override
	public List<Apipra> getAlllist(Pagination pagination) {
		pagination.setStartRow((pagination.getPageIndex() - 1) * pagination.getPageSize());
		List<Apipra> list = apipraMapper.getAlllist(pagination);
		return list;
	}


	@Override
	public void delete(String deleteId) {
		for(String id:deleteId.split(",")){
			Apipra apipra = apipraMapper.selectByPrimaryKey(Integer.parseInt(id));
			apipraMapper.updateByPrimaryKey(apipra);
		}
	}

	@Override
	public boolean getOne(Apipra apipra) {
		ApipraExample example = new ApipraExample();
		example.createCriteria().andCnameEqualTo(apipra.getCname());
		List<Apipra> apipras = apipraMapper.selectByExample(example);
		if(!apipras.isEmpty() && apipras.size() > 0){
			return true;
		}
		return false;
	}


	@Override
	public Apipra selectOne(String deleteId) {
		return apipraMapper.selectByPrimaryKey(Integer.parseInt(deleteId));
	}


	@Override
	public void update(Apipra Apipra) {
		apipraMapper.updateByPrimaryKey(Apipra);
	}


	@Override
	public List<Apipra> getListByAid(Integer appid) {
		return apipraMapper.selectByApiid(appid);
	}

}
